﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ePlanet.SingleWell.Services;
using ePlanet.SingleWell.Models;
using DreamBuilder.Core.Container;
using ePlanet.ArchiveMange.Services;

using Microsoft.Practices.Unity;
using ePlanet.ArchiveMange.Enum;
using CommonModule;
using System.Collections;
using System.Data;

namespace Web.Views.ArchiveFlowView
{
    public partial class AddHandoverDescView : System.Web.UI.Page
    {

        [Dependency]
        public IArchiveMenuService ArchiveMenuService
        {
            get;
            set;
        }

        [Dependency]
        public IPageFileService PageFileService
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {

                    ArrayList idList = null;
                    if (Request.QueryString["from"].Equals("dazl"))     //信息中心-E6
                    {
                        idList = Session["dazl_selectedkeys_jj"] as ArrayList;
                    }
                    else if (Request.QueryString["from"].Equals("dasj")) //档案上交 基层-信息中心
                    {
                        idList = Session["dasj_selectedkeys_jj"] as ArrayList;
                    }
                    else if (Request.QueryString["from"].Equals("dajs")) //档案接收 基层部门领导-信息中心
                    {
                        idList = Session["dajs_selectedkeys_jj"] as ArrayList;
                    }
                    else if (Request.QueryString["from"].Equals("dayj")) //档案移交 机关-信息中心
                    {
                        idList = Session["dayj_selectedkeys_jj"] as ArrayList;

                    }

                    List<string> myIdList = new List<string>();
                    foreach (var id in idList)
                    {
                        myIdList.Add(id.ToString());
                    }

                    int baseTypeId = ArchiveMenuService.GetArchiveBaseIDById(int.Parse(Request.QueryString["archiveType"]));
                    IAttachmentService oIAttachmentService = UContainer.Resolve<IAttachmentService>();
                    DataTable table = null;

                    switch (baseTypeId)
                    {
                        //文书类
                        case ((int)ArchiveBaseType.Document):
                            IDocumentArchiveService documentArchiveService = UContainer.Resolve<IDocumentArchiveService>();
                            table = documentArchiveService.GetDocumentArchiveDataByIds(myIdList);
                            
                            break;
                        //会计类
                        case ((int)ArchiveBaseType.Account):
                            IAccountArchiveService accountArchiveService = UContainer.Resolve<IAccountArchiveService>();
                            table = accountArchiveService.GetAccountArchiveDataByIds(myIdList);
                            
                            break;
                        //基建类
                        case ((int)ArchiveBaseType.BulidProject):
                            IBuildProjectArchiveService buildProjectService = UContainer.Resolve<IBuildProjectArchiveService>();
                            table = buildProjectService.GetBuildProjectArchiveDataByIds(myIdList);
                            
                            break;
                        //设备类
                        case ((int)ArchiveBaseType.Equipment):
                            IEquipmentService equipmentService = UContainer.Resolve<IEquipmentService>();
                            table = equipmentService.GetArchiveDateSpanByIds(myIdList);
                            
                            break;
                        //油气勘探类
                        case ((int)ArchiveBaseType.OliSearch):
                            IOilSearchArchiveService oilSearchService = UContainer.Resolve<IOilSearchArchiveService>();
                            table = oilSearchService.GetArchiveDateSpanByIds(myIdList);
                            
                            break;
                        //音像类
                        case ((int)ArchiveBaseType.AudioVedio):
                            
                            IAudioArchiveService audioService = UContainer.Resolve<IAudioArchiveService>();
                            table = audioService.GetAudioArchiveDataByIds(myIdList);
                            
                            break;
                        //实物类
                        case ((int)ArchiveBaseType.RealKind):
                            IRealKindArchiveService realService = UContainer.Resolve<IRealKindArchiveService>();
                            table = realService.GetHandoverDataByIds(myIdList);
                            break;
                        //科研类
                        case ((int)ArchiveBaseType.Technology):
                            ITechArchiveService techService = UContainer.Resolve<ITechArchiveService>();
                            table = techService.GetHandoverDataByIds(myIdList);

                            
                            break;
                        //光盘类
                        case ((int)ArchiveBaseType.CDKind):
                            ICDArchiveService cdService = UContainer.Resolve<ICDArchiveService>();
                            table = cdService.GetCDArchiveDataByIds(myIdList);

                            
                            break;
                    }

                    txtPageCount.Value = table.Compute("sum(pagenum)", "").ToString();
                }
                catch (System.Exception ex)
                {
                	
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Session["filepagecount"] = txtPageCount.Value;
            Session["filedesc"] = txtHandoverDesc.Value;

            this.RegisterClientScriptBlock("alert",
                string.Format("<script>window.close();opener.navigate('PrintHandoverCatagory.aspx?from={1}&archiveType={0}');</script>"
                , Request.QueryString["archiveType"], Request.QueryString["from"]));

        }

        
    }
}